package com.weiqiao.mall.repository.impl;

import com.mongodb.client.MongoCollection;
import com.weiqiao.base.dao.impl.BaseMongoDaoImpl;
import com.weiqiao.mall.repository.IProductParameterRepository;
import org.bson.Document;
import org.bson.conversions.Bson;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Description: 宝贝参数dao层实现类
 * @author: xujun
 * @Date: 2019/10/26 16:14
 */
@Repository("productParameterRepository")
public class ProductParameterRepositoryImpl extends BaseMongoDaoImpl implements IProductParameterRepository {

    private static final String CONNECTION_NAME = "product_parameter";

    /**
     * 保存宝贝参数实体
     *
     * @param document
     * @return
     */
    @Override
    public boolean create(Document document) {
        return super.inSertDocument(CONNECTION_NAME, document);
    }

    /**
     * 分页查询
     *
     * @param filter   查询条件
     * @param pageable 分页排序数据
     * @return
     */
    @Override
    public List<String> getParameterList(Bson filter, Pageable pageable) {
        return super.getListAndPage(CONNECTION_NAME, filter, pageable);
    }

    @Override
    public List<String> getParameterListByFilter(Bson filter) {
        return super.findFilter(CONNECTION_NAME, filter);
    }

    /**
     * 统计宝贝规格总数
     *
     * @param filter 过滤条件
     * @return boolean 返回整型
     */
    @Override
    public int getParameterCount(Bson filter) {
        MongoCollection<Document> dbCollection = getCollection(CONNECTION_NAME);
        return (int) dbCollection.count(filter);
    }

    /**
     * 删除宝贝参数
     *
     * @param filter
     * @return
     */
    @Override
    public boolean delParameter(Bson filter) {
        return super.deleteOne(CONNECTION_NAME, filter);
    }

    /**
     * 根据条件查询
     *
     * @param filter
     * @return
     */
    @Override
    public String getProductParameter(Bson filter) {
        return super.findOne(CONNECTION_NAME, filter);
    }

    /**
     * 更新宝贝参数
     *
     * @param filter
     * @param document
     * @param bool
     * @return
     */
    @Override
    public boolean updateProductParameter(Bson filter, Document document, Boolean bool) {
        return super.updateOne(CONNECTION_NAME, filter, document, bool);
    }
}
